﻿using System;
using System.Windows.Forms;
using Syncfusion.Windows.Forms;

using PMngr.Data;

namespace PMngr.Main
{
    public partial class UpdateProfile : Office2007Form
    {       
        private IRepositoryFactory repositoryFactory;

        public new string Name { get; set; }

        public UpdateProfile()
        {
            InitializeComponent();
        }

        public UpdateProfile(IRepositoryFactory repositoryFactory, int profileId) : this()
        {
            this.repositoryFactory = repositoryFactory;
            EditCtl.Initialize(repositoryFactory, profileId); 
        }

        private void SaveToolStripMenuItemClick(object sender, EventArgs e)
        {
            using (var repository = repositoryFactory.CreateRepository())
            {
                var profile = EditCtl.GetProfile(repository);
                if (profile != null)
                {
                    profile.ModifiedDate = DateTime.Now;
                    repository.CommitChanges();
                    // set the Name for this dialog
                    Name = profile.Name;

                    DialogResult = DialogResult.OK;
                }
                else
                {
                    DialogResult = DialogResult.None;
                }
            }
        }

    }
}
